<?php

namespace App\Admin\Controllers;

use App\Models\CollPosition;
use App\Models\Product;
use App\Models\ProductAttrKey;
use App\Models\Slide;
use Encore\Admin\Controllers\AdminController;
use App\Admin\Actions\Post\Restore;
use App\Admin\Actions\Post\productSKUList;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;


class SlideController extends AdminController
{
    protected $title = '首页轮播';

    protected function grid()
    {
        $grid = new Grid(new Slide());

        $grid->column('title', __('标题'));
        $grid->column('icon', __('图片'))->image(self::$baseImg, 100, 100);
        $grid->column('url', __('链接'));
        $grid->column('description', __('描述'));

        $grid->column('status', __('状态'))->using(['-1' => '删除', '0' => '未上架', '1' => '正常']);

        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('更新时间'));

        $grid->disableFilter();
        $grid->disableExport();
        $grid->disableRowSelector();
        $grid->disableColumnSelector();

        $grid->actions(function ($actions) {

        });

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(Slide::findOrFail($id));

        $show->field('title', __('标题'));
        $show->field('icon', __('图片'))->image();
        $show->field('url', __('链接'))->carousel();
        $show->field('description', __('描述'));
        $show->field('status', __('状态'))->using(['-1' => '删除', '0' => '未上架', '1' => '正常']);

        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('更新时间'));

        return $show;
    }

    protected function form()
    {
        $form = new Form(new Slide());

        $form->text('title', __('标题'));
        $form->image('icon', __('图片'))->required();
        $form->text('url', __('链接'));
        $form->text('description', __('描述'));

        $status = [
            -1 => '删除',
            0 => '未上架',
            1 => '正常',
        ];

        $form->select('status', '状态')->options($status)->default(1)->required();

        $form->footer(function ($footer) {
            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();
        });

        return $form;
    }
}